package com.woshua.mvpmodel.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.woshua.mvpmodel.R;
import com.woshua.mvpmodel.mvp.model.bean.GirlBean;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class GirlAdapter extends BaseAdapter {

    private List<GirlBean> girls;

    private Context context;

    public GirlAdapter(Context context) {
       this.context=context;
    }

    public void setData(List<GirlBean> girls)
    {
        this.girls = girls;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return this.girls.size();
    }

    @Override
    public Object getItem(int position) {
        return this.girls.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressLint("ViewHolder")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View view = View.inflate(this.context, R.layout.item_girl_info, null);
        ImageView ivIcon = view.findViewById(R.id.iv_item_image);
        TextView tvTitle = view.findViewById(R.id.tv_item_title);

        GirlBean girlBean = this.girls.get(position);
        ivIcon.setImageResource(girlBean.photo);
        tvTitle.setText(girlBean.name);
        return view;
    }
}
